<include file="Public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
  <include file="Public/breadcrumb"/>
  <style type="text/css">
  	.table input{display: none;width: 120px;}
  </style>
  <section class="content">
    <div class="container-fluid">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title"><i class="fa fa-list"></i>商户对账</h3>
        </div>
        <div class="panel-body">    
		<div class="navbar navbar-default">                    
                <form id="search-form2" class="navbar-form form-inline"  method="get" action="{:U('store_duizhang')}">
                <div class="form-group">
				  
                  <div class="input-group">
                    <input type="text" class="form-control" id="store_name" placeholder="店铺名" value="{$Think.request.store_name}" name="store_name" />
                  </div>
				  
                  <div class="input-group">
                    <input type="text" class="form-control" id="account_bank" placeholder="银行卡号" value="{$Think.request.account_bank}" name="account_bank" />                    
                  </div>
                    <button type="button" class="btn btn-primary pull-right" id="daochu"><i class="fa fa-file-excel-o"></i>&nbsp;导出excel</button>

                    <!--                   <div class="input-group margin">
                                        <div class="input-group-addon">
                                            开店时间<i class="fa fa-calendar"></i>
                                        </div>
                                           <input type="text" id="start_time" value="{$Think.request.store_time}" name="store_time" class="form-control pull-right">
                                      </div> -->
                </div>
                <div class="form-group">    
                    <button class="btn btn-primary" id="button-filter search-order" type="submit"><i class="fa fa-search"></i> 筛选</button>    
                </div> 
                </form>
          </div>
         <span style="color: red;">应结算资金为负数，请核实收款/清账再点击结算！</span>
          <div id="ajax_return"> 
                 
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th class="sorting text-center">店铺id</th>
                                <th class="sorting text-center">店铺名称</th>
								<th class="sorting text-center">银行名</th>
								<th class="sorting text-center">银行卡号</th>
								<th class="sorting text-center">开户名</th>
								<th class="sorting text-center">订单金额</th>
								<!-- <th class="sorting text-center">待结列表金额</th> -->
								<th class="sorting text-center">扣点</th>
								<th class="sorting text-center">待结算资金</th>
								<th class="sorting text-center">待退货资金</th>
								<th class="sorting text-center">手续费</th>
                                <th class="sorting text-center">应结算资金</th>
                                <th class="sorting text-center">注册时间</th>
                                <th class="sorting text-center">通联会员编号</th>
                                <th class="sorting text-center">状态</th>
                                <th class="sorting text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <volist name="list" id="v">
                                <tr <?php if($v['result_totals']-$v['store_money']!=0) echo "style='background:#ffeb3b'" ?>>
                                    <td class="text-center">
                                            {$v.store_id}
                                    </td>
                                    <td class="text-center">
                                         {$v.store_name}
                                        <!--<a href="{:U('Store/store_info_edit',array('store_id'=>$v[store_id]))}">-->
                                        <!--     {$v.store_name}-->
                                        <!--</a>-->
                                    </td>                                    
                                    <td class="text-center">{$v.bank_name}</td>
									<td class="text-center">{$v.account_bank}</td>
									<td class="text-center">{$v.account_name}</td>
									<td class="text-center" style="color:#ff9800;"><span>{$v.order_amount}</span>
									<td class="text-center" style="color:#ff9800;"><span>{$v.commis_totals}</span>
									<!-- <td class="text-center" style="color: blue;">{$v.result_totals}</td> -->
									<td class="text-center" style="color: red;"><span>{$v.store_money}</span>
                                    <td class="text-center" style="color: green;"><span>-{$v.tuihuo_price}</span>
                                    <td class="text-center" style="color: blue;"><span>-{$v.commission}</span>
									<td class="text-center" style="color: red;"><span>{$v.yingfu_price}</span>
									<input type="text" onchange="updateSort('store','store_id','{$v.store_id}','store_money',this)" size="4" oninput="$(this).parent().find('span').text($(this).val())" value="{$v.store_money}" class="input-sm">
									</td>
<!--                                    <td class="text-center"><span>{$v.pending_money}</span>
									<input type="text" onchange="updateSort('store','store_id','{$v.store_id}','pending_money',this)" size="4" oninput="$(this).parent().find('span').text($(this).val())" value="{$v.store_money}" class="input-sm">
									</td> -->
                                    <td class="text-center">{$v.store_time|date="Y-m-d",###}</td>
                                <td class="text-center">{$v.tl_userid}</td>
                                <td class="text-center">
                                        <if condition="$v[store_state] eq 0">关闭</if>                                        
                                        <if condition="$v[store_state] eq 1">开启</if>
                                        <if condition="$v[store_state] eq 2">审核中</if>
                                    </td>
                                    <td class="text-center">
                                        <!-- <a href="javascript:" data-toggle="tooltip" rel="{$v.store_id}" class="btn btn-primary" id="pandian" data-original-title="编辑">盘点 <i class="fa fa-pencil"></i></a> -->&nbsp;
										<a href="javascript:" data-toggle="tooltip" rel="{$v.store_id}" class="btn btn-danger" id="jiesuan" data-original-title="结算">结算 <i class="fa fa-pencil"></i></a>
                                    </td>
                                </tr>
                            </volist>
							<tr>
								<td colspan="5" align="right"><b>合计：</b></td>
								<td align="center" style="color:#ff9800;">{$hejiorderprice}</td>
								<td align="right"></td>
								<td align="right"></td>
								<td align="right"></td>
								<td style="font-size: 15px;color: red;text-align: center;">{$hejiprice}</td>
							</tr>
                            </tbody>
                        </table>
                    </div>
                
                <div class="row">
                    <div class="col-sm-6 text-left"></div>
                    <div class="col-sm-6 text-right">{$show}</div>
                </div>
          
          </div>
        </div>
      </div>
    </div>
    <!-- /.row --> 
  </section>
  <!-- /.content --> 
</div>
<!-- /.content-wrapper --> 
 <script>
 // 删除操作
function del(id)
{
	if(!confirm('确定要删除吗?'))
		return false;		
		$.ajax({
			url:"/index.php?m=Admin&c=Finance&a=delStoreWithdrawals&id="+id,
			success: function(v){	
                            var v =  eval('('+v+')');                                 
                            if(v.hasOwnProperty('status') && (v.status == 1))
                               location.href='{:U('Admin/Finance/store_withdrawals')}';
                            else                                
			        layer.msg(v.msg, {icon: 2,time: 1000}); //alert(v.msg);
			}
		}); 
	 return false;
}
 
$(document).ready(function() {
	$('#start_time').daterangepicker({
		format:"YYYY-MM-DD",
		singleDatePicker: false,
		showDropdowns: true,
		minDate:'2020-01-01',
		maxDate:'2030-01-01',
		startDate:'2020-01-01',
	    locale : {
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1
        }
	});
    $("#daochu").click(function(){
        var store_name=$("#store_name").val();
        var account_bank=$("#account_bank").val();
        console.log(store_name);
        layer.confirm('每一页都要点击翻页才能保证数据精准', {
            btn: ['确定','取消'] //按钮
        }, function() {
            location.href = "/index.php/Admin/Finance/export_settlement?store_name=" + store_name + "&account_bank=" + account_bank;
        })
    })
	$(".table #pandian").click(function(){
		var obj=$(this).parent().parent();
		var sshow=obj.find('span');
		if(!sshow.is(':visible')){
			obj.find('input').hide();
			obj.find('span').show();
		}else{
			$(".table input").hide();
			$(".table span").show();
			obj.find('input').show();
			obj.find('span').hide();
		}

	});
	$(".table #jiesuan").click(function(){ //结算
	var store_id=$(this).attr('rel');
	var obj=$(this).parent().parent();
	var remark='已经结算，请留意收款。';
// 		layer.confirm('确定结算？', {
// 		  btn: ['确定','取消'] //按钮
// 		}, function(){
			  layer.prompt({title: '转账备注：', formType: 2,value:'{:date("Y-m-d")}账单结算完成！',allowBlank:true}, function(remark, index){
				$.post('/index.php/Admin/Finance/store_duizhang',{action:'jiesuan',store_id:store_id,remark:remark}
				,function(data){
					if(data==store_id){
						layer.msg('结算成功！', {icon: 6});
						obj.find('input').val('0');
						obj.find('span').text('0');
						location.reload();
					}else{
						layer.msg('结算失败！', {icon: 5});
					}
					layer.close(index);
					console.log(data);
				});
			  });
// 		});
});

});
</script>
</body>
</html>